package com.podhradie.net.themperature.tools;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;

public class Utils {
	
	public static String [] getInterfacesAdress (){
		ArrayList<String> addressList = new ArrayList<String>();
        Enumeration<NetworkInterface> nets;
		try {
			nets = NetworkInterface.getNetworkInterfaces();
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new String [] {"NI exception"};
		}
        
		addressList.add("/0.0.0.0");
        for (NetworkInterface netint : Collections.list(nets)){
        	Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
            for (InetAddress inetAddress : Collections.list(inetAddresses)) {
            	addressList.add(inetAddress.toString());
            }
        	
        }
        
        String []result = new String [addressList.size()];
        return addressList.toArray(result);
    }
}
